package com.dream.springmvc.filter;



import com.dream.springmvc.FieldTypeEnum;
import com.dream.springmvc.FilterDeserializer;
import com.dream.springmvc.value.Value;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import lombok.Data;

/**
 * FilterBase 为所有的过滤器的基类
 * 同时承担条件判断和列表过滤的功能
 *
 * @author zhaoshichang
 */
@Data
@JsonDeserialize(using = FilterDeserializer.class, contentUsing = FilterDeserializer.class)
public abstract class FilterBase<T extends Value<?>> implements Condition<T> {
    private String fieldId;
    private FieldTypeEnum type;
    private T val;

    @Override
    public boolean isMeet(T other) {
        if (!supports(other)) {
            return false;
        }
        return doMeet(other);
    }

    protected abstract boolean supports(Value<?> value);
    protected abstract boolean doMeet(T other);
}